package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.acticle.domain.Travel;
import cn.wolfcode.luowowo.acticle.domain.TravelContent;
import cn.wolfcode.luowowo.acticle.query.TravelQueryObject;
import cn.wolfcode.luowowo.acticle.service.ITravelService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 游记资源管理器
 */
@Controller
@RequestMapping("/travel")
public class TravelController {
    @Reference
    private ITravelService travelService;

    //游记列表
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") TravelQueryObject qo){
        PageInfo pageInfo = travelService .query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "travel/list";
    }
    
    //保存游记
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Travel travel){
        travelService.saveOrUpdate(travel);
        return new AjaxResult();
    }
    //删除游记
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        travelService.delete(id);
        return new AjaxResult();
    }

    //修改游记状态
    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(Long id, Integer state){
        travelService.changeState(id, state);
        return new AjaxResult();
    }

    //查询游记文章
    @RequestMapping("/getTravelContent")
    @ResponseBody
    public Object getTravelContent(Long id){
        TravelContent travelContent = travelService.getTravelContent(id);
        return travelContent;
    }
}
